package com.example.apiproxydemo.core.filter;

import cn.hutool.core.util.StrUtil;
import com.example.apiproxydemo.core.config.代理设置缓存;
import com.example.apiproxydemo.core.model.开放api接口;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.logging.log4j2.SpringBootConfigurationFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

import javax.crypto.spec.OAEPParameterSpec;
import java.util.Map;
import java.util.Optional;

/**
 * @Description
 * @Author zhoupan
 * @Date 2022/2/21 10:38
 */
@Log4j2
@Component()
@Order(-10)
@RequiredArgsConstructor
public class 开放接口过滤器 extends 过滤器抽象类 {
    final 代理设置缓存 代理缓存对象;
    @Override
    Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) {
        //获取请求地址
        String path = exchange.getRequest().getPath().value();
        AntPathMatcher antPathMatcher1 = new AntPathMatcher();
        log.info(path);
        代理设置缓存.开放接口缓存.entrySet().stream().filter(a -> antPathMatcher1.match(a.getValue().get访问路径(),path))
                .map(a->a.getValue())
                .findFirst().orElseThrow(() -> new RuntimeException(StrUtil.format("路径：【{}】未配置", path)));
            return chain.filter(exchange);
    }
}
